package com.sunnyatwal.kettlebell.model;

import android.os.Parcel;
import android.os.Parcelable;

public class SubExercise extends ExerciseUnit
{
	
	private int mWeight;
	private int mReps;
	private int mCurRep;		
	
		
	public SubExercise(String name, int time, int weight, int reps) {
		
		super(tempIcon, name, time);
		
		mWeight = weight;
		mReps = reps;
	}
	
	
	public SubExercise(Parcel p) {
		
		super(p);
		
		mWeight = p.readInt();
		mReps = p.readInt();
		mCurRep = p.readInt();
	}
	
	
	@Override
	public void writeToParcel(Parcel dest, int flags) {
	
		super.writeToParcel(dest, flags);
		dest.writeInt(mWeight);
		dest.writeInt(mReps);
		dest.writeInt(mCurRep);
	}
	
	
	public static final Parcelable.Creator<SubExercise> CREATOR = 
    		new Parcelable.Creator<SubExercise>() {
				@Override
				public SubExercise createFromParcel(Parcel source) {
					return new SubExercise(source);
				}

				@Override
				public SubExercise[] newArray(int size) {
					return new SubExercise[size];
				}
    };
	
    
	public int getWeight() {
		return mWeight;
	}
	
	
	public void setWeight(int weight) {
		this.mWeight = weight;
	}
	
	
	public int getReps() {
		return mReps;
	}
	
	
	public void setReps(int reps) {
		this.mReps = reps;
	}
		
	
	//TODO: abstract
	public String getWeightPretty(boolean includeTitle)
	{
		String ret = mWeight + "kg";
		if(includeTitle)
			ret = "Wgt: " + ret;
		
		return ret;
	}
	
	
	//TODO: abstract
	public String getRepsPretty(boolean includeTitle)
	{
		String ret = mCurRep + "/" + mReps;
		if (includeTitle)
			ret = "Rep: " + ret;
				
		return ret;
	}
	
	
	//TODO: abstract
	public String getTotalRepsPretty(boolean includeTitle) {
		return "Reps: " + mReps;
	}
	
	
	//TODO: abstract
	public int getCurrentRepCompleted()
	{
		float targetTime = (float)(getTotalTime() / mReps);
		float currT = getCurrentTime() - (targetTime * mCurRep); 
		float ret = currT / targetTime;
		
		return  (int) (ret * 100);
	}
	
	
	//TODO: abstract
	@Override
	public String getPrettyNotificationSubText() {
		
		return super.getPrettyNotificationSubText() + "\t\t" + getWeightPretty(true) + "\t\t" + getRepsPretty(true);
	}
	
	
	//TODO: abstract
	@Override
	public String getPrettyListSubText() {
		return super.getPrettyListSubText() + " " + getWeightPretty(true) + " " + getRepsPretty(true);
	}
	
	
	//TODO: abstract
	@Override
	public ElapsedTimeResult ElapseTime(int pCountDownInterval)
	{
		boolean result = super.ElapseTimeBasic(pCountDownInterval);
		
		if ( ((float)(super.getTotalTime() / mReps)) * (mCurRep + 1) < super.getCurrentTime() )
		{
			if(mCurRep < mReps)
				mCurRep++;
		}
		
		return new ElapsedTimeResult(0, result);
	}

	
	
}
